package com.biubiushop.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * 初始化线程池
 * @author chenjia
 */
@Configuration
public class ThreadPoolConfig {
	
	@Bean
	public ThreadPoolTaskExecutor taskExecutor() {
	    ThreadPoolTaskExecutor pool = new ThreadPoolTaskExecutor();
	    // 线程池维护线程的最少数量
	    pool.setCorePoolSize(20);
	    pool.setThreadNamePrefix("ThreadPool_Share_tissue");
	    pool.setKeepAliveSeconds(5);
	    //队列中最大排队线程数
	    pool.setQueueCapacity(20);
	    // 线程池维护线程的最大数量
	    pool.setMaxPoolSize(50);
	    // 当调度器shutdown被调用时等待当前被调度的任务完成
	    pool.setWaitForTasksToCompleteOnShutdown(true);
	    return pool;
	}

}
